<template>
  <div class="top-child">
    <div class="left">
      <span class="lbtn" @click="goHome">首页</span>
    </div>
    <div class="center">
      <div class="title">智慧旅游可视化大数据平台</div>
    </div>
    <div class="right">
      <span class="rbtn">统计报告</span>
      <span class="time">当前时间:{{ currentTime }}</span>
    </div>
  </div>
</template>

<script setup lang="ts">
import { ref, onMounted, onBeforeUnmount } from "vue";
import { useRouter } from "vue-router";
import dayjs from "dayjs";
// 获取路由器对象
const $router = useRouter();
// 存储当前时间
let currentTime = ref(dayjs().format("YYYY年MM月DD日 HH:mm:ss"));
// 定时器对象
let timer = ref();
// 组件挂载完毕后，开启定时时间
onMounted(() => {
  timer.value = setInterval(() => {
    currentTime.value = dayjs().format("YYYY年MM月DD日 HH:mm:ss");
  }, 1000);
});
// 组件销毁之前，清除定时器
onBeforeUnmount(() => {
  clearInterval(timer.value);
});

// 跳转首页
const goHome = () => {
  $router.push("/home");
};
</script>

<style scoped lang="scss">
.top-child {
  width: 100%;
  height: 100%;
  display: flex;
  .left {
    flex: 1.3;
    background: url(../../images/dataScreen-header-left-bg.png);
    background-size: cover;
    .lbtn {
      float: right;
      width: 150px;
      height: 40px;
      background: url(../../images/dataScreen-header-btn-bg-l.png);
      background-size: 100% 100%;
      text-align: center;
      line-height: 40px;
      color: #29fcff;
      font-size: 20px;
      cursor: pointer;
    }
  }
  .right {
    flex: 1.3;
    background: url(../../images/dataScreen-header-right-bg.png);
    background-size: cover;
    display: flex;
    justify-content: space-between;
    align-items: center;
    .rbtn {
      width: 150px;
      height: 40px;
      background: url(../../images/dataScreen-header-btn-bg-r.png);
      background-size: 100% 100%;
      text-align: center;
      line-height: 40px;
      color: #29fcff;
      font-size: 20px;
      cursor: pointer;
    }
    .time {
      color: #29fcff;
      font-size: 20px;
      margin-right: 10px;
    }
  }
  .center {
    flex: 2;
    .title {
      width: 100%;
      height: 74px;
      background: url(../../images/dataScreen-header-center-bg.png);
      background-size: 100% 100%;
      text-align: center;
      line-height: 74px;
      color: #29fcff;
      font-size: 30px;
    }
  }
}
</style>
